<template>
  <div style="height:100%;width:100%">
    <el-row class="mainContent" >
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="filters" size="small" style="text-align:left;" :rules="filte" ref="filters">
          <el-form-item >
            <el-input v-model="filters.mobile" placeholder="手机号" clearable></el-input>
          </el-form-item>
          <el-form-item >
            <el-input v-model="filters.nickname" placeholder="用户名" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <div class="block">
              <el-date-picker
                v-model="filters.begtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
              <el-date-picker
                v-model="filters.endtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  @click="getUsers">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <!--列表-->
      <el-table :data="users" highlight-current-row  v-loading="listLoading" style="width: 100%;">
        <el-table-column  label="手机号"  >
          <template slot-scope="scope">
            {{scope.row.dataInfo.mobile}}
          </template>
        </el-table-column>
        <el-table-column label="用户名" >
          <template slot-scope="scope">
            {{scope.row.dataInfo.nickname}}
          </template>
        </el-table-column>

        <el-table-column  label="姓名" >
          <template slot-scope="scope">
            {{scope.row.dataInfo.realname}}
          </template>
        </el-table-column>
        <el-table-column  label="可用余额" prop="financeInfo.amountAvailable">
        </el-table-column>
        <!--<el-table-column  label="子账号"  >-->
        <!--<template slot-scope="scope">-->
        <!--{{scope.row.financing.subUsername}}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column  label="子账号资产"  >-->
        <!--<template slot-scope="scope">-->
        <!--{{scope.row.financing.amount}}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column  label="注册时间"  prop="regTime">
        </el-table-column>
        <el-table-column  label="操作" v-if="$store.state.routes.routes.yhDetail || $store.state.routes.routes.yhxxczOperate || $store.state.routes.routes.yhWater">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="$router.push({path:'userDetail',query:{id:scope.row.id,from:'userConfig'}})" v-if="$store.state.routes.routes.yhDetail">详情</el-button>
            <el-button
              size="mini"
              type="text"
              @click="rechargeDown(scope.$index, scope.row)" v-if="$store.state.routes.routes.yhxxczOperate">线下充值</el-button>
            <el-button
              size="mini"
              type="text"
              @click="$router.push({path:'userWaterDetail',query:{id:scope.row.id,from:'userConfig',name:scope.row.dataInfo.nickname,realname:scope.row.dataInfo.realname,mobile:scope.row.dataInfo.mobile}})" v-if="$store.state.routes.routes.yhWater">资金流水</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10"  :total="total" style="float:right;">
      </el-pagination>
    </el-row>
    <el-dialog title="线下充值" :visible.sync="dialogFormVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="editForm" ref="editPwdForm" status-icon label-width="100px" :rules="editFormRules" style="text-align:left">
        <el-form-item label="用户名" >
          <el-col :span="22">
            <el-input v-model="editForm.nickname" placeholder="" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-col :span="22" class="orderId">
            <el-input type="text" v-model="editForm.realname" placeholder=""disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手机号" >
          <el-col :span="22">
            <el-input type="text"  v-model="editForm.mobile" placeholder="" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="可用余额" >
          <el-col :span="22">
            <el-input type="text"  v-model="editForm.avaliable" placeholder="" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="财务密码" >
          <el-col :span="22">
            <el-input type="password"  v-model="editForm.finPassword" ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="金额" >
          <el-col :span="22">
            <el-input type="text"  v-model="editForm.amount" ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native="submitDialog" :loading="editPwdLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        filters: {
          nickname:'',
          mobile:'',
          begtime:'',
          endtime:"",
        },
        editForm:{},
        editFormRules:{},
        users:[],
        page: 1,
        total: 0,
        listLoading: false,
        filte:{},
        dialogFormVisible:false,
        editPwdLoading:false
      };
    },
    created() {
      this.getUsers();
    },
    methods: {
      getUsers() {
        this.users = []
        this.listLoading = true;
        var obj = {
          data:{
            nickname:this.filters.nickname,
            mobile:this.filters.mobile,
            begtime:this.filters.begtime==''||this.filters.begtime==0||this.filters.begtime==null?'':Math.round(new Date(this.filters.begtime).getTime()/1000),
            endtime:this.filters.endtime==''||this.filters.endtime==0||this.filters.endtime==null?'':Math.round(new Date(this.filters.endtime).getTime()/1000),
            pageNo:this.page,
          }
        };
        this.$http('sys/user/listUser.do',obj).then(resp => {
          if(resp.code==1){
            this.users = resp.data.list;
            this.total = resp.data.total
          }
          this.listLoading = false;
        });

      },
      handleCurrentChange(val) {
        this.page = val;
        this.getUsers();
      },
      rechargeDown(index,row){
        if(!this.$store.state.routes.routes.yhxxczOperate){
          this.$message({
            message:'无权限',
            type:'error'
          })
          return
        }
        this.editForm.id = row.id;
        this.editForm.nickname = row.dataInfo.nickname;
        this.editForm.realname = row.dataInfo.realname;
        this.editForm.mobile = row.dataInfo.mobile;
        this.editForm.avaliable = row.financeInfo.amountAvailable;
        this.editForm.finPassword = '';
        this.editForm.amount = '';
        this.dialogFormVisible = true;
      },
      submitDialog(){
        if(this.editForm.finPassword == ''){
          this.$message({
            message:'财务密码不能为空',
            type:'error'
          })
          return
        }
        if(this.editForm.amount == ''){
          this.$message({
            message:'充值金额不能为空',
            type:'error'
          })
          return
        }
        this.editPwdLoading = true;
        var obj = {
          data:{
            userid:this.editForm.id,
            finPassword: this.editForm.finPassword,
            amount:this.editForm.amount
          }
        };
        this.$http('sys/recharge/line.do',obj).then(resp=> {
          if(resp.code!=1){
            this.$message({
              message:resp.msg,
              type:'error'
            })
          }else{
            this.$message({
              message:'充值成功',
              type:'success'
            })
          }
          this.getUsers()
          this.editPwdLoading = false
        })
        this.dialogFormVisible = false;
        this.editForm = {}

      },

    }
  };
</script>

<style scoped>


  .el-table:hover{
    cursor: pointer !important;
  }
</style>
